home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / palis.lha / Palis / src / vpl / Lists.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  7KB  |  354 lines

  1. /*
  2.     ·C·O·D·E·X· ·D·E·S·I·G·N· ·S·O·F·T·W·A·R·E·
  3.     presents
  4.  
  5.     PatchLibraries Utility / VIEW
  6.  
  7.     FILE:    lists.c
  8.     TASK:    do list work
  9.  
  10.     (c)1995 by Hans Bühler, h0348kil@rz.hu-berlin.de
  11. */
  12.  
  13. #include    "plView.h"
  14.  
  15. // ---------------------------
  16. // defines
  17. // ---------------------------
  18.  
  19. #define    BUFLEN    199
  20.  
  21. // ---------------------------
  22. // datatypes
  23. // ---------------------------
  24.  
  25. // ---------------------------
  26. // proto
  27. // ---------------------------
  28.  
  29. static BOOL MakeTxtList(char *txtLines[]);
  30. static BOOL MakePalisList(void);
  31. static BOOL ConvertPalisList(struct plBase *plBase);
  32. static struct Line *AllocLine(struct MinList *list, WORD len);
  33. static void InitEmptyList(struct MinList *List);
  34. static void RemList(void);
  35.  
  36. // ---------------------------
  37. // vars
  38. // ---------------------------
  39.  
  40. // ---------------------------
  41. // funx
  42. // ---------------------------
  43.  
  44. static char    *InfoLines[]    =
  45.     {
  46. //        "12345678901234567890123456789012345678901234"
  47.         "",
  48.         " ·C·O·D·E·X· ·D·E·S·I·G·N· ·S·O·F·T·W·A·R·E·",
  49.         "    presents:",
  50.         "",
  51.         " " PROGNAME_FULL,
  52.         "",
  53.         " This little commodity has  been designed to",
  54.         "view all patches PALIS V1+ had tracked.",
  55.         " PALIS is required to use this program.",
  56.         " PALIS (The PatchLib Solution!! ;^) had been",
  57.         "programmed in order to avoid conflicts  when",
  58.         "some programs patch libraries. It will track",
  59.         "all patches  and will take  appropiate steps",
  60.         "when a program  attempts to remove its patch",
  61.         "later.",
  62.         " PALIS  might be  ordered from the author or",
  63.         "copied from the aminet (dev/misc).",
  64.         " PALIS and ViewPALIS are freely copyable !",
  65.         "",
  66.         "Programmed by Hans Bühler,",
  67.         "              Codex Design Software",
  68.         "              Kirchstr.22",
  69.         "              D-10557 Berlin",
  70.         "eMail: h0348kil@rz.hu-berlin.de",
  71.         0
  72.     },
  73.     *NoPatchesLines[]    =
  74.     {
  75.         "No patch reported from PALIS !",
  76.         0
  77.     },
  78.     *NoPalisLines[]    =
  79.     {
  80. //        "12345678901234567890123456789012345678901234"
  81.         "--------------------------------------------",
  82.         "ERROR: PALIS V1+ not found.",
  83.         "--------------------------------------------",
  84.         "",
  85.         "Please run PALIS \"The PatchLib Solution\" and",
  86.         "retry.",
  87.         0
  88.     },
  89.     *NoMemLines[]    =
  90.     {
  91.         "--------------------------------------------",
  92.         "ERROR: Out of memory !",
  93.         "--------------------------------------------",
  94.         0
  95.     },
  96.     *NoReadLines[]    =
  97.     {
  98.         "--------------------------------------------",
  99.         "ERROR: PALIS refused to answer !",
  100.         "       Have you commanded to quit PALIS ?",
  101.         "--------------------------------------------",
  102.         0
  103.     },
  104.     *GurkLines[]    =
  105.     {
  106.         "Unknown command.",
  107.         0
  108.     };
  109.  
  110. char    *RemovedTxt        =    "<removed> ",
  111.         *EndTxt            =    "[END]";
  112.  
  113. // ---------------------------
  114.  
  115. struct MinList    ActiveList    =    {    0    };
  116.  
  117. // ---------------------------
  118. // funx: global
  119. // ---------------------------
  120.  
  121. #define    iSetAttrs(GDX)    if(MainWnd)    GT_SetGadgetAttrs(MainGadgets[GDX],MainWnd,0,
  122. #define    ADONE                TAG_DONE)
  123.  
  124. void SetActiveList(UBYTE listID)
  125. {
  126.     BOOL    ok;
  127.  
  128.     iSetAttrs(GDX_GadList)    GTLV_Labels,    ~0,    ADONE;
  129.  
  130.     switch(listID)
  131.     {
  132.         case    LIST_PALIS    :    ok    =    MakePalisList();
  133.                                     break;
  134.         case    LIST_ABOUT    :    ok    =    MakeTxtList(InfoLines);
  135.                                     break;
  136.         default                :    ok    =    MakeTxtList(GurkLines);
  137.                                     break;
  138.     }
  139.  
  140.     if(!ok)
  141.         if(!MakeTxtList(NoMemLines))        // frees all allocated lines
  142.             ErrorReq("Out of memory !",0,0,0,0);
  143.  
  144.     iSetAttrs(GDX_GadList)    GTLV_Labels,    &ActiveList,    ADONE;
  145. }
  146.  
  147. BOOL InitLists(void)
  148. {
  149.     InitEmptyList(&ActiveList);
  150.  
  151.     return TRUE;
  152. }
  153.  
  154. void RemLists(void)
  155. {
  156.     RemList();
  157. }
  158.  
  159. // ---------------------------
  160. // funx: local
  161. // ---------------------------
  162.  
  163. /************************************************
  164.  * delete active list                                    *
  165.  * Each node will be freed by AllocVec()            *
  166.  * => be sure a node and all data are allocated    *
  167.  * by one step.                                            *
  168.  ************************************************/
  169.  
  170. static void RemList(void)
  171. {
  172.     struct Line    *line;
  173.  
  174.     while(line = (struct Line *)RemHead((struct List *)&ActiveList))
  175.         FreeVec(line);
  176. }
  177.  
  178. /**********************************************
  179.  * Eine liste aus einem string-array aufbauen *
  180.  **********************************************/
  181.  
  182. static BOOL MakeTxtList(char *txtLines[])
  183. {
  184.     struct Line        *line;
  185.     int                i;
  186.  
  187.     RemList();
  188.  
  189.     for(i=0; txtLines[i]; i++)
  190.     {
  191.         if(!( line = AllocVec(sizeof(struct Line), MEMF_PUBLIC|MEMF_CLEAR) ))
  192.             return FALSE;
  193.  
  194.         line->Text    =    txtLines[i];
  195.  
  196.         AddTail((struct List *)&ActiveList, &line->Node);
  197.     }
  198.  
  199.     return TRUE;
  200. }
  201.  
  202. /************************************
  203.  * Die PALIS process list erstellen *
  204.  ************************************/
  205.  
  206. static BOOL MakePalisList(void)
  207. {
  208.     struct plBase        *plBase;
  209.     BOOL                    erg;
  210.  
  211.     RemList();
  212.  
  213.     // -- erstmal neue Liste --
  214.  
  215.     if(!(plBase = (struct plBase *)FindSemaphore(PALIS_SEMAPHORE_NAME)))
  216.         return MakeTxtList(NoPalisLines);
  217.  
  218.     ObtainSemaphoreShared(&plBase->Sem);
  219.  
  220.     if(!plBase->PatchCnt)
  221.         erg    =    MakeTxtList(NoPatchesLines);
  222.     else
  223.         erg    =    ConvertPalisList(plBase);
  224.  
  225.     ReleaseSemaphore(&plBase->Sem);
  226.  
  227.     return erg;
  228. }
  229.  
  230. // ----------------------------
  231.  
  232. static BOOL ConvertPalisList(struct plBase *plBase)
  233. {
  234.     struct plLib        *plLib;
  235.     struct plOffset    *plOff;
  236.     struct plPatch        *plPatch;
  237.     struct Line            *line;
  238.     char                    buf[BUFLEN+1];
  239.     int                    i;
  240.     BOOL                    first;
  241.  
  242.     // -- now start --
  243.  
  244.     for(    plLib = (APTR)plBase->LibList.mlh_Head;
  245.             plLib->Node.mln_Succ;
  246.             plLib = (APTR)plLib->Node.mln_Succ)
  247.     {
  248.         // -- "library [1 offset(s) patched]" --
  249.  
  250.         sprintf(buf,"%s [%ld offset(s) patched]",    plLib->Lib->lib_Node.ln_Name,
  251.                                                                 plLib->OffCnt);
  252.  
  253.         if(!( line = AllocLine(&ActiveList,strlen(buf)+1) ))
  254.             return FALSE;
  255.  
  256.         strcpy(line->Text,buf);
  257.  
  258.         // -- "----------------------------" --
  259.  
  260.         if(!( line = AllocLine(&ActiveList,strlen(buf)+1) ))
  261.             return FALSE;
  262.  
  263.         for(i=0; i<strlen(buf); i++)
  264.             line->Text[i]    =    '-';
  265.  
  266.         line->Text[i]    =    0;
  267.  
  268.         // -- "" --
  269.  
  270.         if(!( line = AllocLine(&ActiveList,1) ))
  271.             return FALSE;
  272.  
  273.         line->Text[0]    =    0;
  274.  
  275.         for(    plOff = (APTR)plLib->OffList.mlh_Head;
  276.                 plOff->Node.mln_Succ;
  277.                 plOff    = (APTR)plOff->Node.mln_Succ)
  278.         {
  279.             // -- offset selbst nicht ausgeben --
  280.  
  281.             first    =    TRUE;
  282.  
  283.             for(    plPatch = (APTR)plOff->PatchList.mlh_Head;
  284.                     plPatch->Node.mln_Succ;
  285.                     plPatch = (APTR)plPatch->Node.mln_Succ)
  286.             {
  287. //                ErrorReq("offset $%lx: %ld ('%s')",plOff,(APTR)plOff->Offset,plPatch->ProcName,0);
  288.  
  289.                 if(first)
  290.                 {
  291.                     sprintf(buf,"%6ld %s%s",
  292.                                 plOff->Offset,
  293.                                 PL_ACTIVE(plPatch) ? 0 : RemovedTxt,
  294.                                 plPatch->ProcName);
  295.                 }
  296.                 else
  297.                     sprintf(buf,"       %s%s",
  298.                                 PL_ACTIVE(plPatch) ? 0 : RemovedTxt,
  299.                                 plPatch->ProcName);
  300.  
  301.                 first    =    FALSE;
  302.  
  303.                 // -- "  -120 Process" --
  304.  
  305.                 if(!( line = AllocLine(&ActiveList,strlen(buf)+1) ))
  306.                     return FALSE;
  307.  
  308.                 strcpy(line->Text,buf);
  309.             }
  310.         }
  311.  
  312.         if(!( line = AllocLine(&ActiveList,1) ))
  313.             return FALSE;
  314.  
  315.         line->Text[0]    =    0;
  316.     }
  317.  
  318.     if( line = AllocLine(&ActiveList,0) )
  319.         line->Text    =    EndTxt;
  320.  
  321.     return TRUE;
  322. }
  323.  
  324. // ---------------------------
  325.  
  326. static struct Line *AllocLine(struct MinList *list, WORD len)
  327. {
  328.     struct Line    *line;
  329.  
  330.     if(!( line = AllocVec(sizeof(struct Line) + len, MEMF_PUBLIC) ))
  331.         return 0;
  332.  
  333.     line->Text    =    &((char *)line)[sizeof(struct Line)];
  334.  
  335.     AddTail((struct List *)list,&line->Node);
  336.  
  337.     return line;
  338. }
  339.  
  340. // ---------------------------
  341. // funx: list set
  342. // ---------------------------
  343.  
  344. /*******************
  345.  * init empty list *
  346.  *******************/
  347.  
  348. static void InitEmptyList(struct MinList *List)
  349. {
  350.     List->mlh_Head        =    (struct MinNode *)&List->mlh_Tail;
  351.     List->mlh_Tail        =    0;
  352.     List->mlh_TailPred=    (struct MinNode *)&List->mlh_Head;
  353. }
  354.